<template>
  <div id="luckySheetContainer"
       style="margin:0px;padding:0px;position:absolute;width:100%;height:800px;left: 0px;top: 0px;"></div>

</template>
<script setup>
import {onMounted, ref, toRaw, inject, getCurrentInstance, provide} from "vue";
import api from '../request/apis'
import moment from "moment";
import {Col, Message} from 'view-ui-plus'
import LuckyExcel from "luckyexcel";

const blobToFile = (blob, fileName) => {
  const file = new File([blob], fileName);
  return file;
}
const callBack = function (workbookBlob, fileName) {
  const file = blobToFile(workbookBlob, fileName);
  // alert(1)
  LuckyExcel.transformExcelToLucky(file, function (
      exportJson,
      luckysheetfile
  ) {
    if (exportJson.sheets == null || exportJson.sheets.length == 0) {
      this.$message.warning("读取excel文件内容失败，目前不支持xls文件!");
      return;
    }
    console.log(exportJson.sheets);

    // console.log(exportJson.sheets)
    luckysheet.create({
      container: "luckySheetContainer",
      showinfobar: false,
      data: exportJson.sheets,
      lang: 'zh',
      title: exportJson.info.name,
      userInfo: exportJson.info.name.creator
    });
  });

}

onMounted(() => {
  window.luckysheet.create({
    container: "luckySheetContainer",
    showinfobar: false,
    // data: [],
    lang: 'zh',
    title: "预览",
    userInfo: "system"
  });
})

// provide("callBack",callBack);
// 暴露clearForm方法和msgson属性给父组件
defineExpose({callBack})
</script>
<style scoped>
</style>